<!DOCTYPE html>
<html>
  <head>
    <title>注册</title>
    <%- include('../head') %>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
     <style type="text/css">
     	*{
    		padding: 0;
    		margin: 0;
    	}
    	body{
    		font-size: 0.30rem;
    	}
    	h1{
    		background:#649efd;
    		font-size: 0.4rem;
    		text-align: center;
    		color: #fff;
    		padding: 0.1rem;
    		margin-bottom: 0.5rem;
    	}
    	p.inp{
    		border: 1px solid #649efd;
    		margin-bottom: 0.2rem;
    	}
    	p.inp input{
    		box-sizing: border-box;
    		width: 100%;
    		height: 0.80rem;
    		border:none;
    		outline: none;
    		text-indent: 1em;
    	}
    	p button{
    		width: 100%;
    		height: 0.8rem;
    	}
    	p.sign{
    		padding-top: 2rem;
    		padding-bottom: 0.2rem;
    		text-align: center;
    		
    	}
     </style>
  </head>
  <body>
    <h1>注册</h1>
    <p class="inp">
    	<input type="text" placeholder="用户名" name="username" id="username" value="" />
    </p>
    <p class="inp">
    	<input type="text" placeholder="密码" name="password" id="password" value="" />
    </p>
    <p class="sign"><a href="/signin" class="loginTo">登录</a></p>
    <p class="btt">
    	<button class="btn">注册</button>
    </p>
  </body>
  <script type="text/javascript" src="/javascripts/jquery.js"> </script>
  <script type="text/javascript">
  	
	$(".btn").on("click",function(){
		var name = $("#username").val().trim();
		var pwd = $("#password").val().trim();
		$.ajax({
			type:"post",
			url:"/api/user/signup",
			data:{
				name:name,
				password:pwd
			},
			success:function(data){
			
				console.log(data);
				if(data.code == 1){
					window.location.href = '/signin';
				}else{
					alert(data.message);
				}
			},
			error:function(error){
				console.log(error);
			}
		});
	});
  </script>
</html>
